#ifndef Utils_H
#define Utils_H
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/euler_angles.hpp>


inline static glm::mat4 ExtractRotationMatrix(const glm::mat4 &m, const glm::vec3 &scale)
{
    return glm::mat4(m[0] / scale.x, m[1] / scale.y, m[2] / scale.z, glm::vec4(0, 0, 0, 1.0f));
}

inline static glm::mat4 ExtractRotationMatrixKeepM3(const glm::mat4 &m, const glm::vec3 &scale)
{
    return glm::mat4(m[0] / scale.x, m[1] / scale.y, m[2] / scale.z, m[3]);
}

inline static glm::quat ExtractQuaternion(const glm::mat4 &m)
{
    return glm::quat_cast(m);
}

inline static glm::vec3 ExtractScale(const glm::mat4 &m)
{
    glm::vec3 s;
    s.x = glm::length(glm::vec3(m[0]));
    s.y = glm::length(glm::vec3(m[1]));
    s.z = glm::length(glm::vec3(m[2]));
    return s;
}

inline static glm::vec3 ExtractTranslation(const glm::mat4 &m)
{
    glm::vec3 t;
    t.x = m[3][0];
    t.y = m[3][1];
    t.z = m[3][2];
    return t;
}

#endif // Utils_H